/*
 * Created by Jaren at 2021/12/20 10:19
 */
import 'package:inmotion_protocol/common/product_version.dart';
import 'package:inmotion_protocol/common/vehicle_info.dart';
import 'package:inmotion_protocol/lorin/bean/scooter/c1/c1_settings.dart';
import 'package:inmotion_protocol/lorin/bean/scooter/scooter_settings.dart';
import 'package:inmotion_protocol/lorin/factory/special/scooter/scooter_message_factory.dart';
import 'package:inmotion_protocol/lorin/lorin_message.dart';
import 'package:inmotion_protocol/util/byte_util.dart';

class C1MessageFactory extends ScooterLorinSpecialMessageFactory<_C1Cmd> {
  C1MessageFactory(ProductProperty productProperty) : super(productProperty);

  @override
  void initCompact(int apiVersion, VersionWrapper version) {
    compact = C1CmdDefault();
  }

  /// C1 Pro骑行模式定义不同
  /// see [C1Settings.toRidingMode]
  @override
  LorinMessage genSetRidingModeMsg(int mode) {
    if (productProperty.model.isLC1Pro()) {
      // C1 Pro助推模式标识为0
      if (mode == ScooterSettings.ridingModeAssist) mode = 0;
    }
    return super.genSetRidingModeMsg(mode);
  }

  LorinMessage genSetSpeedLimitOfAssistModeMsg(int speedLimit) {
    return genSpecialOne2OneWriteMsg(compact!.speedLimitOfAssistModeCmd(), ByteUtil.num2BytesLe(speedLimit, 2));
  }
}

abstract class _C1Cmd extends ScooterCmdCompact {
  int speedLimitOfAssistModeCmd();
}

class C1CmdDefault extends _C1Cmd {
  @override
  int speedLimitOfAssistModeCmd() {
    return 32;
  }
}
